Skip to content

fix: Entity::normalizeValue() must handle UnitEnum before toArray()#10137

Open
maniaba wants to merge 6 commits into
codeigniter4:developfrom
maniaba:bug-entity
Open

fix: Entity::normalizeValue() must handle UnitEnum before toArray()#10137
maniaba wants to merge 6 commits into
codeigniter4:developfrom
maniaba:bug-entity

Conversation

@maniaba
Copy link
Copy Markdown
Contributor

@maniaba maniaba commented Apr 24, 2026

Description

Moves the UnitEnum instanceof check before JsonSerializable and method_exists($data, 'toArray') in Entity::normalizeValue(), so that enums implementing toArray() are always normalized as enums rather than as generic objects.

Fixes #10136

  • fix test: correct toRawArray() assertion for injected enum

toRawArray() returns raw $this->attributes, so an injected enum object stays as an enum object — not the backing string value. The real regression is that hasChanged() must return false (normalizeValue() handles UnitEnum before toArray()).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@patel-vansh
Copy link
Copy Markdown
Contributor

You need to add this fix in v4.7.3 changelog

Comment thread tests/_support/Enum/StateEnum.php
Comment thread tests/system/Entity/EntityTest.php Outdated
@github-actions github-actions Bot added the stale Pull requests with conflicts label Apr 26, 2026
@github-actions

This comment was marked as resolved.

@maniaba maniaba requested a review from michalsn April 26, 2026 15:14
@paulbalandan paulbalandan added bug Verified issues on the current code behavior or pull requests that will fix them and removed stale Pull requests with conflicts labels Apr 26, 2026
Comment thread system/Entity/Entity.php Outdated
Comment thread system/Entity/Entity.php
Comment thread system/Entity/Entity.php
@paulbalandan paulbalandan changed the title fix: Entity::normalizeValue() must handle UnitEnum before toArray() fix: Entity::normalizeValue() must handle UnitEnum before toArray() Apr 26, 2026
@github-actions github-actions Bot added the stale Pull requests with conflicts label May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

👋 Hi, @maniaba!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@michalsn michalsn removed the stale Pull requests with conflicts label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Entity::normalizeValue incorrectly handles enums when they implement toArray()

4 participants